package com.enation.app.javashop.api.client;

import com.enation.app.javashop.service.trade.pintuan.PinTuanSearchManager;
import com.enation.app.javashop.service.trade.pintuan.PintuanGoodsManager;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author fk
 * @version v2.0
 * @Description: 商品服务对外client
 * @date 2018/7/30 15:06
 * @since v7.0.0
 */
@Api(description = "商品相关API")
@RestController
@RequestMapping("/client/pintuan")
@Validated
@ApiIgnore
public class PintuanGoodsClientController {

    @Autowired
    private PintuanGoodsManager pintuanGoodsManager;

    @Autowired
    private PinTuanSearchManager pinTuanSearchManager;

    @PostMapping(value = "/promotion/{promotion_id}")
    public boolean createGoodsIndex(@PathVariable("promotion_id")Long promotionId) {
        return  pintuanGoodsManager.addIndex(promotionId);
    }

    @PostMapping(value = "/goods/{goods_id}/del")
    public void deleteIndexByGoodsId(@PathVariable("goods_id")Long goodsId) {
        pinTuanSearchManager.deleteByGoodsId(goodsId);
    }

    @PostMapping(value = "/goods/{goods_id}/sync-index")
    public void syncIndexByGoodsId(@PathVariable("goods_id")Long goodsId) {
        pinTuanSearchManager.syncIndexByGoodsId(goodsId);
    }

    @RequestMapping(value = "/goods/{goods_id}/del-all", method = RequestMethod.POST)
    void delete(@PathVariable("goods_id")Long goodsId){
        this.pintuanGoodsManager.delete(goodsId);
    }

    @DeleteMapping("/goods")
    public void deletePinTuanGoods(@RequestBody List<Long> delSkuIds) {
        pintuanGoodsManager.deletePinTuanGoods(delSkuIds);
    }
}
